package Server;

import Data.GroupData;

import java.io.IOException;
import java.sql.*;
import java.util.ArrayList;

public class SetAllGroupToUser {
    //需要找出用户的所有的群聊消息

    private String id;

    String url = "jdbc:mysql://127.0.0.1:3306/nox?useUnicode=true&characterEncoding=UTF-8&userSSL=false&serverTimezone=GMT%2B8";
    String user = "root";
    String password = "Mi20030610.";

    public ArrayList<GroupData> setAllGroup() throws ClassNotFoundException, SQLException, IOException {
        Class.forName("com.mysql.cj.jdbc.Driver");
        Connection Conn = DriverManager.getConnection(url, user, password);
        String sql="select *from group_identity_list where id=?";
        ArrayList<GroupData> arrayList=new ArrayList<>();

        PreparedStatement operation=Conn.prepareStatement(sql);
        operation.setString(1,id);

        ResultSet resultSet=operation.executeQuery();
        while(resultSet.next())
        {
            String group_id=resultSet.getString("group_id");
            int identity=resultSet.getInt("identity");

            SetGroup setGroup=new SetGroup();
            GroupData groupData=setGroup.setgroup(group_id);

            groupData.setIdentity(identity);
            groupData.setGroup_id(group_id);
            groupData.setId(id);

            System.out.println("找到了群聊id为"+group_id+"我的身份为"+identity);
            if(groupData.getIdentity()!=0)
            {
                arrayList.add(groupData);
            }
        }
        return arrayList;
    }

    public SetAllGroupToUser(String id) {
        this.id = id;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }
}
